home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: How to embed a part into yourself (long)
- Sent: 6/13/96 6:09 PM
- Received: 6/13/96 6:21 PM
- From: Damon Cokenias, cokenias@mtn-palace.com
- Reply-To: ODF Interest, ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- >Can someone point me to sample code or a routine that shows how to create a
- >part at run-time and embed in another part. For example, in response to the
- >user choosing the text tool from a palette and dragging a rectangle, create
- >a text part and embed it at the location the user specified.
-
- Mark, I meant to put together a little note about this just last week but
- forgot. Sorry.
-
- I've done this in one of our internal parts here at Apple. There are a few
- steps, none too difficult.
-
- First, create an ODShape to be used as the frame shape. Remember that the
- top-left corner of a frame shape should be {0,0} regardless of where the
- part will appear in your content. (More on location later).
-
-
- FW_CAcquiredODShape frameShape = FW_NewODShape (ev, bounds);
-
- Second, you need to obtain a reference to your document's draft and ask the
- draft to create a new ODPart. Given an FW_CPart, the following code will
- work:
-
- ODStorageUnit* su = myPart -> GetStorageUnit (ev);
- ODDraft* draft = su -> GetDraft (ev);
- FW_CAcquiredODPart newPart = draft ->
- CreatePart (ev, kTextKind, kODNoEditor);
-
- Note that in the above code, kTextKind would be the full ISO string
- describing the kind of data to be embedded. kODNoEditor signifies that
- OpenDoc should feel free to choose which editor to use for the embedded
- data. Instead, this parameter could be an ISO string for a particular
- editor.
-
- Third, you need to construct a proxy object to represent the embedded part
- within yor content model. See ODFEmbed and ODFDraw for examples of proxy
- objects. Depending on your content model you may need a very simple or
- very complicated proxy object.
-
- CMyProxy* myProxy = new CMyProxy (ev, myPart,
- myPart -> GetMainPresentation ());
-
- Finally, embed the newly created part in your content:
-
- myPart -> GetMainPresentation () -> Embed (ev, newPart, NULL,
- kODFrameObject,
- myProxy, frameShape, FW_CPart::gViewAsFrameToken,
- NULL, 0,
- FALSE, FALSE);
-
- These many parameters could use some explaining:
-
- ev That obnoxious SOM thing that almost every function
- takes as a
- parameter
- newPart The ODPart created by our document's draft
- NULL The ODFrame to embed. In our case, we want a frame
- created for
- us.
- kODFrameObject Suggested frame type.
- myProxy The subclass of FW_MProxy that will represent the
- embedded
- content.
- frameShape The frame shape, with its origin at {0,0}
- gViewAsFrameToken A tokenized ISO string describing how to embed the
- part. (As
- icon, thumbnail, frame, etc.)
- NULL Presentation type. NULL for default.
- 0 Frame group ID.
- FALSE Is overlaid
- FALSE Is subframe
-
-
-
-
- Once the above steps have been taken, the containing frame's
- CreateEmbeddedFacet method will be called. This is where you decide where
- to position the embedded content and how much of it to display.
-
- Often you will simply want a facet that is the same size and shape as the
- frame shape, just at a particular location in your frame. The code below
- positions the embedded part at {40,100}.
-
- ODFacet* CMyFrame::CreateEmbeddedFacet (Environment* ev, ODFacet*
- embeddingFacet,
- FW_MProxy* proxy, ODFrame* embeddedFrame,
- ODShape* proposedClipShape) {
-
- FW_CAcquiredODTransform externalTransform;
-
- externalTransform = ::FW_NewODTransform (ev, FW_CPoint
- (FW_IntToFixed (40),
- FW_IntToFixed (100)));
-
-
- return embeddeingFacet -> CreateEmbeddedFacet (ev, embeddedFrame,
- proposedClipShape, externalTransform, NULL, NULL, NULL,
- kODFrameInFront);
- }
-
- Once again, a quick breakdown of the parameters. First, the values passed
- to CreateEmbeddedFacet:
-
- ev Your favorite and mine.
- embeddingFacet The containing facet.
- proxy Your subclass of FW_MProxy that was passed to
- FW_CEmbeddingPresentation::Embed in the code above.
- embeddedFrame The frame of the embedded part that will draw in the facet
- you create.
- proposedClipShape This shape describes the shape of the facet that
- the embedded
- part would prefer to use. It is at {0,0}.
-
-
- The parameters to CreateEmbeddedFacet:
-
- ev How much time gets spent passing this parameter anyway?
- embeddedFrame The embedded frame
- proposedClipShape The (in this case unaltered) shape to use. If you
- want to use
- a shape other than the proposed shape, you should create
- another shape object, not mess with the
- proposedClipShape
- directly.
- externalTransform Where in the parent facet (your part's facet) the
- embedded
- facet should appear.
- NULL The canvas. NULL means use same canvas as
- containing part.
- NULL The biasCanvas. NULL because we are not using any funky
- drawing coordinates.
- NULL A sibling facet. If there is already a facet for this
- embedded frame, pass it here.
- kODFrameInFront Where the facet should be in relation to its
- sibling. This
- does not really apply in this situation because
- there is only
- one facet for this frame.
-
-
-
- Whew!
-
-
-
-
- If you remove all of my comments and maybe fix a spelling error or two,
- you'll probably be able to compile the above directly in to your part.
-
- I hope this was of help!
-
- -Damon
- Quality ODF Guy
-
-
- +-----------------------------------------------------------------------+
- | /\ Damon Cokenias |
- | /^^\ cokenias@mtn-palace.com |
- | /____\ Visit the Mountain Palace at http://www.netgate.net/~cokenias |
- +-----------------------------------------------------------------------+
-
-